/***************************************************************************************************
 *Copyright(C),2010-2017,Sumscope
 *FileName	:  DictExport.h
 *Author	:  scofined.qi
 *Version	:  1.0
 *Date		:  2017/04/19
 *Desc		:  用于将新字典导出为旧字典的格式:cod,文本文件,|分割
 *Relation :
 *Others	:
 *Function :
 *History	:
 ***************************************************************************************************/
#pragma once

#include <core/strings/string_aes.h>
#include <string.h>

#include <QFile>
#include <string>
#include <vector>

#include "HTable/src/TableColumn.h"

namespace qb {
namespace ht {
class DictExport {
 public:
  enum kConvertType {
    kConvertTypeNone,
    kConvertTypeBlank,
    kConvertTypeYesNo,
    kConvertTypeCount
  };

 protected:
  char* m_buffer;
  int m_capcity;
  int m_size;
  int m_col_added;
  QFile* m_file;
  char m_double_format[32];
  qb::base::StringAes* m_tagger;
  bool m_encrypt;
  bool m_hasconverter;
  std::vector<kConvertType>
      m_converts;  // 以FieldDesc.offset为索引,没有设置就是kConvertTypeNone
 public:
  DictExport(int capcity, int precision, const std::string& tag = "");
  ~DictExport();
  bool Init(const char* fullFileName);
  void AddLineEnd();
  void AddData(kDataType type, int offset, const char* data, int len);

  void AddConverter(const char* name, int offset, kConvertType type);

 protected:
  kConvertType GetConvertTypeByOfffset(int offset) {
    if (m_hasconverter && offset >= 0 && offset < (int)m_converts.size())
      return m_converts[offset];
    return kConvertTypeNone;
  }
  void AddString(const char* str, int len);
  void Flush();
};

}  // namespace ht
}  // namespace qb
